home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / cd-sup / hippoplayer / arexx / hippoplay.filer < prev    next >
Text File  |  1998-05-24  |  18KB  |  477 lines

  1. /* HippoPlayer ARexx script for Filer.                      (v 1.2) *
  2.  * ================================================================ *
  3.  *                                                                  *
  4.  * Adds selected files into HiP's playlist and randomplays them.    *
  5.  * If HiP isn't already running it is run first.                    *
  6.  *                                                                  *
  7.  * If directories were selected this script recurses through all    *
  8.  * subdirectories, so it is possible to add all your modules to     *
  9.  * HiP's playing list just by selecting your module directory!      *
  10.  *                                                                  *
  11.  * If nothing was selected (user just pushed the button) then       *
  12.  * we tell HiP to Random Play with it's current playlist unless     *
  13.  * there's only one module in it, in which case we eject it.        *
  14.  * But if the playlist is empty already we advice the user to       *
  15.  * select a module before fooling around...                         *
  16.  *                                                                  *
  17.  *------------------------------------------------------------------*
  18.  * NOTE! This script checks if a file has a suffix or prefix that   *
  19.  * indicates something else than a module, for example "foo.info",  *
  20.  * "program.readme" or ".backdrop". Unfortunately this also makes   *
  21.  * the script noticeably slower, so this feature is disabled by     *
  22.  * default. If you want to use it, see CONFIGURATION below.         *
  23.  *------------------------------------------------------------------*
  24.  *                                                                  *
  25.  * Version 1.2: now supports double-clicking of modules! This is    *
  26.  * done by adding the following line to the end of your Filer.RC:   *
  27.  *                                                                  *
  28.  * CLASS "(mod|MED).#?","","RX HippoPlay.filer %f"                  *
  29.  *                                                                  *
  30.  ***** Requirements: rexxsupport.library, HiP, and Filer...    ******
  31.  * Remember to replace the HippoPath variable below with the        *
  32.  * correct path of HiP in your system! You might also want to set   *
  33.  * HiP's screen to FilerScreen in the HiP-prefs, though this script *
  34.  * opens HiP on FilerScreen automatically anyway.                   *
  35.  *                                                                  *
  36.  * Sorry for the messyness, especially in dirpart, but it works! :) *
  37.  * If it fails for you, contact me:                                 *
  38.  * Janne Simonen - jsimonen@cc.joensuu.fi                           */
  39.  
  40.  
  41. /* -------------------------------------------------------------------- */
  42. /**** CONFIGURATION: change the following lines to suit your system! ****/
  43. /* -------------------------------------------------------------------- */
  44.  
  45. HippoPath = 'dh2:HippoPlayer/Hip'               /* Where to find HiP    */
  46.  
  47. /* This flag controls the printing of extra information on FilerScreen. */
  48. /* 0 = OFF, 1 = ON. If you don't have composers' names in filenotes and */
  49. /* don't want to know how big the mod is, switch this off.              */
  50.  
  51. Verbose = 1                                     /* Default: speak up!   */
  52.  
  53. /* This flag turns filename checking on/off, 0 = OFF, 1 = ON    */
  54.  
  55. CheckFileNames = 0  /* Default: don't check filenames for ".info"s etc. */
  56.  
  57. /* These suffixes/prefixes indicate that a file really is NOT a module! */
  58. /* You can add your own, just remember to change crapnumbers accordingly*/
  59. /* The more you add, the slower the script gets, so...                  */
  60.  
  61. IF ~(CheckFileNames = 0) THEN DO    /* if checking is not disabled  */
  62.  
  63.     crapsufnumber = 3               /* number of crap suffixes  */
  64.     crapsuffix.1 = '.info'          /* disregard these suffixes */
  65.     crapsuffix.2 = '.readme'
  66.     crapsuffix.3 = '.doc'
  67.  
  68.     crapprefnumber = 1              /* number of crap prefixes  */
  69.     crapprefix.1 = '.'              /* disregard these prefixes */
  70. END
  71.  
  72. ELSE DO         /* if checking is disabled then accept ALL files    */
  73.     crap = 0    /* regardless of filename. Don't change this!       */
  74. END
  75.  
  76. /* Random play if nothing selected? If not then show modinfo    */
  77.  
  78. RandPlay = 0
  79.  
  80.  
  81. /* -------------------------------------------------------------------- */
  82. /* ******************* MAIN PROGRAM STARTS HERE *********************** */
  83. /* -------------------------------------------------------------------- */
  84.  
  85. OPTIONS RESULTS
  86. PARSE ARG doubleclickname   /* Read possible argument (double-clicked mod) */
  87.  
  88. SIGNAL ON IOERR    /* Trap for IO-Errors (filehandling etc.)    */
  89. SIGNAL ON BREAK_C  /* Trap for control-c break (doesn't work?)  */
  90.  
  91. /********** Make sure HiP is running (with an open ARexx port) **********/
  92.  
  93. IF ~SHOW("Ports","HIPPOPLAYER") THEN DO
  94.     ADDRESS 'FilerRexx'
  95.     'STATUS Loading HippoPlayer...'
  96.     ADDRESS 'COMMAND' 'run >NIL: '||HippoPath
  97.     
  98.     /* give HiP exactly 5 seconds time to emerge */
  99.     ADDRESS 'FilerRexx'
  100.     'STATUS Waiting for HippoPlayer to open its ARexx port...'
  101.     TIME('R')
  102.     DO WHILE ((TIME('E')<5) & (~SHOW("Ports","HIPPOPLAYER")))
  103.     END
  104.     
  105.     IF ~SHOW("Ports","HIPPOPLAYER") THEN DO
  106.         ADDRESS 'FilerRexx'
  107.         "STATUS HippoPlayer didn't show up!"
  108.         EXIT
  109.     END
  110.  
  111.     ADDRESS 'HIPPOPLAYER'
  112.     'PUBSCREEN FilerScreen'     /* open HiP on FilerScreen  */
  113.     'ZIP 0'                     /* and zip the window.      */
  114. END
  115.  
  116. /****************** Check if a file was double-clicked ******************/
  117.  
  118. IF ~( doubleclickname = "" ) THEN DO
  119.  
  120.     /* remove possible '"'s from the file name, because they're  */
  121.     /* automatically added by ARexx below. */
  122.     doubleclickname = COMPRESS( doubleclickname, '"' )
  123.  
  124.     ADDRESS 'HIPPOPLAYER'
  125.     'CLEAR'
  126.     'ADD '||doubleclickname     /* Add the mod to Hip's playlist */
  127.  
  128.     Message = 'HiP: Adding module "'||doubleclickname||'" into playlist...'
  129.     IF LENGTH( Message ) < 67 THEN DO
  130.         Message = OVERLAY( 'Please wait!', Message, 68)
  131.     END
  132.  
  133.     ADDRESS 'FilerRexx'
  134.     'STATUS '||Message              /* tell user what's happening   */
  135.  
  136.     ADDRESS 'HIPPOPLAYER'
  137.     'CHOOSE 1'
  138.     'PLAY'                          /* tell hip to make some noise  */
  139.  
  140.     'GET PLAY'                      /* check if anything is playing */
  141.     IF RESULT = 0 THEN DO           /* if not -> we're very sorry...*/
  142.       ADDRESS 'FilerRexx'           /* ...probably out of memory    */
  143.       "STATUS HiP: Sorry, can't play this one!"
  144.     END
  145.  
  146.     EXIT                            /* Enough done, let's retire... */
  147. END
  148.  
  149. /****** Open a lib to get SHOWDIR() to be used with directories  ********/
  150.  
  151. CALL ADDLIB('rexxsupport.library', 0, -30, 0)
  152.  
  153. /********************* Give HiP the modules to play *********************/
  154.  
  155. ADDRESS 'FilerRexx'
  156.  
  157. /* Get source directory name, append "/" if it is not a device name     */
  158. GETSOURCEPATH
  159. srcdir = RESULT
  160. IF RIGHT( srcdir, 1 ) ~= ":" THEN srcdir = srcdir || "/"
  161.  
  162. GETNUMENTRIES                   /* get number of sourcedir entries  */
  163. numentries = RESULT
  164.  
  165. DO j = 1 TO numentries          /* loop through all entries         */
  166.   GETNAME j                     /* get jth entry                    */
  167.   entry = RESULT
  168.  
  169.   type = LEFT( entry, 1 )       /* parse filetype (f, d, F, D)      */
  170.   name = SUBSTR( entry, 2 )     /* parse filename                   */
  171.  
  172.   SELECT                        /* it's either a file OR a directory*/
  173.  
  174.     /* If entry is a selected FILE we add it to playlist            */
  175.  
  176.     WHEN type = 'f' THEN DO
  177.  
  178.       IF CheckFileNames = 1 THEN DO     /* if checking not disabled     */
  179.         CALL FileCheck                  /* check if it's a module       */
  180.       END
  181.  
  182.       IF crap = 0 THEN DO               /* if it is, then lets add...   */
  183.  
  184.         IF checkflag ~= 'TRUE' THEN DO  /* if it's the first file to    */
  185.           ADDRESS 'HIPPOPLAYER'         /* add we clear the playlist    */
  186.           'CLEAR'
  187.           checkflag = 'TRUE'
  188.         END
  189.  
  190.         ADDRESS 'FilerRexx'
  191.                                         /* just finetuning the message..*/
  192.         Message = 'HiP: Adding module "'||name||'" into playlist...'
  193.         IF LENGTH( Message ) < 67 THEN DO
  194.           Message = OVERLAY( 'Please wait!', Message, 68)
  195.         END
  196.  
  197.         'STATUS '||Message              /* tell user what's happening   */
  198.         ADDRESS 'HIPPOPLAYER'
  199.         'ADD '||srcdir||name            /* add the file into playlist   */
  200.  
  201.       END /* IF - FileCheck   */
  202.  
  203.       ADDRESS 'FilerRexx'
  204.       TOGGLEENTRY j                     /* de-select                    */
  205.  
  206.     END /* WHEN */
  207.  
  208.     /* If entry is a DIRECTORY we scan it through and see what's in     */
  209.  
  210.     WHEN type = 'd' THEN DO
  211.  
  212.       Dirname = srcdir||name
  213.       /* get a string containing the filenames separated with a '0a'x   */
  214.       Filelist = SHOWDIR( Dirname, 'FILE', '0a'x )
  215.       /* if string not empty we append a '0a'x (to make things work...) */
  216.       IF Filelist ~= '' THEN Filelist = Filelist || '0a'x
  217.  
  218.       CALL FileNameParser   /* add all the files in the dir to playlist */
  219.  
  220.       /* See if there are any SUBDIRECTORIES and scan them for files    */
  221.  
  222.       i = 1                                         /* recursion level  */
  223.       CALL DirRecurser      /* let's delve through the subdirectories   */
  224.       ADDRESS 'FilerRexx'
  225.       TOGGLEENTRY j
  226.  
  227.     END /* WHEN - DIRECTORY */
  228.  
  229.     OTHERWISE                   /* ignore entries not selected          */
  230.  
  231.   END /* SELECT */
  232.  
  233. END /* DO j */
  234.  
  235. /* -------------------------------------------------------------------- */
  236. /* Ok, we've scanned all selected files/dirs and added the files to     */
  237. /* playlist, now it's time to do some bonus stuff...                    */
  238. /* -------------------------------------------------------------------- */
  239.  
  240. /* If no file (or module! FileNameCheck...) was selected then:          */
  241.  
  242. IF checkflag ~= "TRUE" THEN DO
  243.  
  244.     ADDRESS 'HIPPOPLAYER'
  245.     'GET NFIL'                    /* get number of files in playlist    */
  246.     numberoffiles = RESULT
  247.  
  248.     /* if only non-module files were selected then this helps us complain */
  249.     IF NameCheckFlag = 1 THEN numberoffiles = 0
  250.  
  251.     IF numberoffiles = 1 THEN DO  /* if it's one we eject the mod       */
  252.         'CLEAR'
  253.         'EJECT'
  254.         ADDRESS 'FilerRexx'
  255.         'STATUS HiP: Ejected the only module in the playlist.'
  256.         EXIT
  257.     END
  258.  
  259.     IF numberoffiles = 0 THEN DO  /* Nothing playing? Let's complain    */
  260.         ADDRESS 'FilerRexx'
  261.         'STATUS HiP: It might help if you selected a module to play! :)'
  262.         EXIT
  263.     END
  264.  
  265.     IF RandPlay = 0 THEN
  266.     CALL DisplayStuff   /* Show info if multiple entries in playlist*/
  267.  
  268. END
  269.  
  270. ADDRESS 'FilerRexx'
  271. 'STATUS HiP: Loading module, please wait...'
  272.  
  273. ADDRESS 'HIPPOPLAYER'
  274.  
  275. 'GET NFIL'                          /* get number of files in playlist  */
  276.                                     /* because RANDPLAY doesn't work    */
  277. IF RESULT = 1 THEN DO               /* if there's only one file...      */
  278.     'CHOOSE 1'                      /* ...at least not with HiP207.     */
  279.     'PLAY'
  280. END                                 /* single file: let's play it.      */
  281. ELSE 'RANDPLAY'                     /* multiple files: Random Play.     */
  282.  
  283. 'GET PLAY'                          /* check if anything is playing     */
  284. playornot = RESULT
  285. IF playornot = 0 THEN DO            /* if not -> we're very sorry...    */
  286.     ADDRESS 'FilerRexx'             /* ...probably out of memory        */
  287.     "STATUS HiP: Sorry, can't play this one!"
  288.     EXIT
  289. END
  290.  
  291. DisplayStuff:
  292. /* Now a mod is playing, so we just display some info on FilerScreen    */
  293.  
  294. 'GET NAME'                          /* get mod name so that we can show */
  295. modname = RESULT                    /* it on Filer's statusbar          */
  296.  
  297. IF modname = '' THEN DO             /* if modname doesn't exist         */
  298.     'GET CNAM'                      /* we simply use filename           */
  299.     modname = RESULT
  300.                                     /* strip off any prefix (like mod.) */
  301.     /* a little fix for a bug in HiP207: CNAM gives path too! K-P? :)   */
  302.     DivPos = max(lastpos(':', modname),lastpos('/', modname)) +1
  303.     modname = substr(modname, DivPos)
  304.     modname = substr(modname, lastpos('.', modname, 6) +1)
  305.  
  306. END /* IF */
  307.  
  308. modname = SPACE( modname, 1)        /* remove extra spaces from name    */
  309.  
  310. IF Verbose = 0 THEN DO              /* if Verbose is switched off we    */
  311.     ADDRESS 'FilerRexx'             /* only tell the module's name      */
  312.     'STATUS HiP: Playing "'||modname'"'
  313.     EXIT                            /* and exit.*/
  314. END
  315.  
  316. 'GET COMM'                          /* get filenote/comment because     */
  317. comment = RESULT                    /* I have the composer's name in it */
  318.  
  319. IF comment = '' THEN DO             /* no comment? Then give type&size  */
  320.     'GET TYPE'                      /* instead to have some chrome :)   */
  321.     modtype = RESULT
  322.     'GET SIZE'
  323.     modsize = RESULT
  324.  
  325.     comment = 'HiP: Playing '||modtype||' module "'||modname'"'
  326.  
  327.                             /* check that announcement fits on screen   */
  328.     IF LENGTH( comment ) < 61 THEN DO
  329.         comment = comment || ', size '||modsize||' bytes'
  330.     END
  331.                                     /* announce what HiP is playing     */
  332.     ADDRESS 'FilerRexx'             /* with modtype and modsize         */
  333.     'STATUS ' || comment
  334.  
  335. END /* IF */
  336.  
  337. ELSE DO
  338.     comment = 'by ' || comment      /* announce with composer's name    */
  339.     ADDRESS 'FilerRexx'
  340.     'STATUS HiP: Playing "'||modname||'" '||comment
  341. END /* ELSE */
  342.  
  343. EXIT                                /* voilá! */
  344.  
  345.  
  346. /* -------------------------------------------------------------------- */
  347. /*************** END OF MAIN PROGRAM, SUBROUTINES FOLLOW ****************/
  348. /* -------------------------------------------------------------------- */
  349.  
  350.  
  351. FileNameParser:
  352. /* Parses filenames from the string 'Filelist' and adds them to playlist*/
  353. /* Gets the complete path from the variable 'Dirname'.                  */
  354. /* Filelist looks like "file1'0a'xfile2'0a'xfile3'0a'xfile4'0a'x".      */
  355.  
  356.  DO WHILE POS( '0a'x, Filelist ) > 0    /* while we still have files    */
  357.  
  358.     Slashpos = POS( '0a'x, Filelist )   /* find the next separator      */
  359.     name = LEFT( Filelist, Slashpos -1) /* extract filename             */
  360.  
  361.     IF CheckFileNames = 1 THEN DO
  362.       CALL FileCheck                    /* see if it is a module        */
  363.     END
  364.  
  365.     IF crap = 0 THEN DO                 /* if yes, add it to playlist:  */
  366.  
  367.       IF checkflag ~= 'TRUE' THEN DO    /* if this is the first file    */
  368.           ADDRESS 'HIPPOPLAYER'         /* to add to playlist then      */
  369.           'CLEAR'                       /* clear the list first         */
  370.           checkflag = 'TRUE'
  371.       END
  372.  
  373.       ADDRESS 'FilerRexx'
  374.                                         /* just finetuning the message..*/
  375.       Message = 'HiP: Adding module "'||name||'" into playlist...'
  376.       IF LENGTH( Message ) < 67 THEN DO
  377.           Message = OVERLAY( 'Please wait!', Message, 68)
  378.       END
  379.  
  380.       'STATUS '||Message
  381.       ADDRESS 'HIPPOPLAYER'
  382.       'ADD '||Dirname||'/'||name        /* add the mod to playlist      */
  383.  
  384.     END /* IF - FileCheck */
  385.                                 /* Strip out added filename from string */
  386.     Filelist = SUBSTR( Filelist, Slashpos +1)
  387.  
  388.  END /* WHILE */
  389.  
  390. RETURN /* END OF SUBROUTINE ----------------------------------------*/
  391.  
  392.  
  393. DirRecurser:
  394. /* Recurses through all the subdirectories of a directory, then     */
  395. /* calls FileNameParser to add the files in them into playlist.     */
  396.  
  397. /* Get list of subdirectories                                       */
  398. Dirlist.i = SHOWDIR( Dirname, 'DIR', '0a'x)
  399. IF Dirlist.i ~= '' THEN Dirlist.i = Dirlist.i || '0a'x
  400.  
  401. /* Go through the subdirs one by one, adding any files to playlist  */
  402. DO WHILE POS( '0a'x, Dirlist.i ) > 0
  403.  
  404.     Slashpos = POS( '0a'x, Dirlist.i )          /* find the divider */
  405.     dname = LEFT( Dirlist.i, Slashpos -1)       /* get subdirname   */
  406.     Dirlist.i = SUBSTR( Dirlist.i, Slashpos +1) /* strip it off     */
  407.  
  408.     Dirnamebak.i = Dirname                /* take backup of Dirname */
  409.     Dirname = Dirname || '/' ||dname      /* make subdirectorypath  */
  410.  
  411.     Filelist = SHOWDIR( Dirname, 'FILE', '0a'x)    /* make filelist */
  412.     IF Filelist ~= '' THEN Filelist = Filelist || '0a'x
  413.  
  414.     CALL FileNameParser     /* add any files in subdir to playlist  */
  415.  
  416.     i = i + 1                           /* increase recursion level */
  417.  
  418.     CALL DirRecurser        /* call subroutine itself recursively   */
  419.  
  420.     i = i - 1                           /* decrease recursion level */
  421.  
  422.     Dirname = Dirnamebak.i              /* get back saved Dirname   */
  423. END
  424.  
  425. RETURN  /* END OF SUBROUTINE -----------------------------------*/
  426.  
  427.  
  428. FileCheck:
  429. /* Checks if file clearly is not a module (.info .readme...)    */
  430. /* Gets the filename from a global variable called "name"       */
  431. /* If file is not a mod, returns crap = 1, else returns crap=0. */
  432. /* Bad suf(/pre)fixes are stored in crapsuf(/pre)fix variable.  */
  433.  
  434. a = 1
  435.  
  436. DO WHILE a < (crapsufnumber+1)
  437.     /* Check suffix */
  438.     IF RIGHT( name, LENGTH( crapsuffix.a ) ) = crapsuffix.a THEN DO
  439.         crap = 1            /* file is not a module!        */
  440.         NameCheckFlag = 1   /* a non-module file was found  */
  441.         RETURN
  442.     END
  443.     a = a + 1
  444. END
  445.  
  446. a = 1
  447.  
  448. DO WHILE a < (crapprefnumber+1)
  449.     /* Check prefix */
  450.     IF LEFT( name, LENGTH( crapprefix.a ) ) = crapprefix.a THEN DO
  451.         crap = 1            /* file is not a module!    */
  452.         NameCheckFlag = 1   /* a non-mod was selected   */
  453.         RETURN
  454.     END
  455.     a = a + 1
  456. END
  457.  
  458. crap = 0    /* file passed the check - it's no crap! :) */
  459.  
  460. RETURN      /* END OF SUBROUTINE -------------------------------*/
  461.  
  462.  
  463. IOERR:      /* I/O-Error trap, not tested, might even work...   */
  464.  
  465. ADDRESS 'FilerRexx'
  466. 'STATUS HiP: Sorry, an I/O-error has occurred on line '||SIGL||'!'
  467. 'ALERTBOX I/O error - something is wrong!|File "'||name||'" was being processed.'
  468. EXIT
  469.  
  470.  
  471. BREAK_C:    /* Break trap, never had this work...   */
  472.  
  473. ADDRESS 'FilerRexx'
  474. "STATUS HiP: Break request detected - I won't play anything!"
  475. 'NONE'
  476. EXIT
  477.